<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Base Sprite</title>
</head>
<body>
  <canvas id="mycanvas" width="600" height="600"></canvas>
  <!-- <script src="https://unpkg.com/spritejs@2.24.12/dist/spritejs.min.js"></script> -->
  <script src="/js/sprite-core.js"></script>
  <script>
    const Sprite = spritejs.Sprite;
    const Layer = spritejs.Layer;
    const Group = spritejs.Group;
    const context = document.getElementById('mycanvas').getContext('2d');
    const layer = new Layer({context, renderMode: 'repaintAll'});

    const g = new Group({
      enterMode: 'onebyone',
      exitMode: 'onebyone-reverse',
    });
    const s1 = new Sprite({
      anchor: 0.5,
      pos: [100, 300],
      size: [100, 100],
      bgcolor: 'red',
      opacity: 1,
      id: 's1',
      states: {
        beforeEnter: {
          opacity: 0,
        },
        afterExit: {
          opacity: 0,
        },
      },
      actions: [
        {
          from: 'beforeEnter',
          duration: 2000,
        },
      ],
    });

    const s2 = s1.cloneNode();
    s2.attr({x: x => x + 200, id: 's2'});
    
    const s3 = s2.cloneNode();
    s3.attr({x: x => x + 200, id: 's3'});
    
    g.append(s1, s2, s3);
    layer.append(g);
  </script>
</body>
</html>